package com.example.children.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.children.DTO.AttendanceTeacherDTO;
import com.example.children.DTO.ClassDTO;
import com.example.children.DTO.HeadToClassDTO;
import com.example.children.DTO.TeacherClassDTO;
import com.example.children.FileService.ClassInterface;
import com.example.children.Mapper.ClassMapper;
import com.example.children.Model.Class;
import com.example.children.Model.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service  //考勤
public class ClassService extends ServiceImpl<ClassMapper, Class> implements ClassInterface {

        @Autowired
        private ClassMapper classMapper;

    public void update(Class ct) {
        classMapper.updateByIdMy(ct);
    }

    // 根据 id 删除
    public void delete(String classId) {
        classMapper.deleteByIdMY(classId);
    }



    public boolean addStudentToClass(HeadToClassDTO headToClassDTO) {
        classMapper.insert(headToClassDTO);
        return true;
    }

    public boolean IsSaveTeacher(HeadToClassDTO headToClassDTO) {
        return classMapper.IsSaveTeacher(headToClassDTO);
    }

    public boolean IsSaveStudent(HeadToClassDTO headToClassDTO) {
        return classMapper.IsSaveStudent(headToClassDTO);

    }

    public boolean addStudentToClass_two(HeadToClassDTO headToClassDTO) {
        classMapper.insert_two(headToClassDTO);
        return true;
    }

    public Page<ClassDTO> GetClassPage(int pageNo, int pageSize) {
        // 计算分页的偏移量
        int offset = (pageNo - 1) * pageSize;

        // 获取当前页的数据
        List<ClassDTO> records = classMapper.GetClassPage(offset, pageSize);
        // 获取总记录数
        int total = classMapper.countTotalRecords();
        // 构造并返回分页对象
        Page<ClassDTO> page = new Page<>();
        page.setTotal(total);
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        page.setRecords(records);

        return page;
    }

    public void insertClass(Class ct) {
          classMapper.insertClass(ct);
    }

    public List<TeacherClassDTO> ManySelectClass(TeacherClassDTO teacherClassDTO) {
        return classMapper.selectToClasss(teacherClassDTO);
    }
}
